//
//  YSLCommodityViewController.m
//  used
//
//  Created by lanou on 16/7/16.
//  Copyright © 2016年 王凯. All rights reserved.
//

#import "YSLCommodityViewController.h"

@interface YSLCommodityViewController ()<UMSocialUIDelegate, CommodityViewDelegate>
/** 模型 */
@property (nonatomic, strong) KLCommodity *model;

@property (nonatomic, strong) NSMutableArray *collectionArray;

@property (nonatomic, strong) NSMutableArray *dataSource;

@property (nonatomic, strong)CommodityView *commodityView;

@end

@implementation YSLCommodityViewController

- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

- (NSMutableArray *)collectionArray{
    
    if (!_collectionArray) {
        _collectionArray = [NSMutableArray array];
    }
    return _collectionArray;
}

- (CommodityView *)commodityView {

    if (!_commodityView) {
        _commodityView = [[NSBundle mainBundle] loadNibNamed:@"CommodityView" owner:nil options:nil].lastObject;
        
        _commodityView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);
        _commodityView.delegate = self;
    }

    return _commodityView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"商品详情";                                                                    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"fishpond_share_icon" highImage:nil target:self action:@selector(shareAction)];
    [self.view addSubview:self.commodityView];
    self.commodityView.backgroundColor = KLRGBColor(240, 240, 240);
        [self loadData];
}

- (void)loadData{
    
    [RequestManager fetchDataWithUrl:@"http://m.jiuaixianzhi.com/api/v4/goodsdetail/ioscommon/" parameter:@{@"goodsid":self.goodsID} method:@"POST" compeleted:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
 
        self.model = [KLCommodity mj_objectWithKeyValues: bigDic[@"result"]];
        self.commodityView.commodityModel = self.model;
        self.commodityView.ID =  bigDic[@"result"][@"id"];

    } updateUI:^{
//        [self reloadData];
        
    }];
}

//  分享
- (void)shareAction {
    
    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImage url:self.model.sharecontent[@"shareicon"]];
    [UMSocialData defaultData].extConfig.title = self.model.sharecontent[@"sharetitle"];
    [UMSocialData defaultData].extConfig.qqData.url = self.model.sharecontent[@"shareurl"];
    [UMSocialSnsService presentSnsIconSheetView:self appKey:@"579186aae0f55a6e91001036" shareText:self.model.sharecontent[@"sharedesc"] shareImage:[UIImage imageNamed:@"icon"]
    shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToQQ]
                                       delegate:self];
}

#pragma mark - <CommodityViewDelegate>
- (void)clictIconMessageWithUserid:(NSNumber *)userid {
    
    KLSellerViewController *sellerVc = [[KLSellerViewController alloc] init];
    sellerVc.userID = userid;
    [self.navigationController pushViewController:sellerVc animated:YES];
}




@end
